<template>
  <view class="bg-gradient-to-r from-blue-50 to-blue-100 min-h-screen w-[750rpx] box-border bgs">
    <PageHeader title="" :showBack="true" :onlyBack="true" />
    <view class="bg-gradient-to-r sticky top-0 z-[2] from-blue-600 to-purple-600 text-white p-[40rpx] text-center relative overflow-hidden">
      <view class="absolute w-[300rpx] h-[300rpx] bg-white bg-opacity-10 rounded-full -top-[100rpx] -right-[80rpx]"> </view>
      <view class="absolute w-[200rpx] h-[200rpx] bg-white bg-opacity-8 rounded-full -bottom-[80rpx] -left-[60rpx]"> </view>

      <text class="text-[42rpx] font-bold mb-[10rpx] block relative z-2">实名认证</text>
      <text class="text-[26rpx] opacity-90 relative z-2">开启个人创业之旅，共享平台资源与机遇</text>
    </view>
    <view class="px-[32rpx] py-[64rpx]">
      <!-- Rules Cards -->
      <view class="flex flex-wrap gap-[30rpx] mb-[40rpx]">
        <view class="flex-1 min-w-[300rpx] bg-white rounded-[20rpx] p-[35rpx] shadow-lg">
          <view class="text-[32rpx] font-semibold mb-[25rpx] text-blue-500 flex items-center">
            <!-- <IconFont name="id-card" class="mr-[15rpx] text-[32rpx]" /> -->
            <text class="mr-1">🔸</text>
            <text>实名认证规则</text>
          </view>
          <view class="text-[26rpx] leading-[1.8]">
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">每个身份证号码仅限认证一个平台账号</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">请确保提交的身份证信息真实有效</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">认证信息将用于平台交易安全保障</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">实名认证通过后方可开始接单</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative text-red-500 font-medium">
              <text class="text-red-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">虚假认证将导致账号永久封禁</text>
            </view>
          </view>
        </view>

        <view class="flex-1 min-w-[300rpx] bg-white rounded-[20rpx] p-[35rpx] shadow-lg">
          <view class="text-[32rpx] font-semibold mb-[25rpx] text-blue-500 flex items-center">
            <text class="mr-1">🔸</text>
            <text>处罚规则</text>
          </view>
          <view class="text-[26rpx] leading-[1.8]">
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]"><text class="font-bold">第一次违规：</text>平台警告通知</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]"><text class="font-bold">第二次违规：</text>账号冻结7天</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]"><text class="font-bold">第三次违规：</text>账号永久封禁</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative text-red-500 font-medium">
              <text class="text-red-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">账号封禁后选择删除账号：</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">系统记录该身份证信息</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">一年内禁止使用同一身份证注册</text>
            </view>
            <view class="mb-[15rpx] pl-[10rpx] relative">
              <text class="text-blue-500 font-bold absolute left-0">•</text>
              <text class="ml-[20rpx]">一年内禁止在平台接单</text>
            </view>
          </view>
        </view>
      </view>

      <!-- Form Section -->
      <view class="bg-white rounded-xl mb-[64rpx] overflow-hidden">
        <view class="h-[8rpx] bg-gradient-to-r from-blue-500 to-blue-600"></view>

        <view class="p-[48rpx]">
          <view class="text-[36rpx] font-semibold text-blue-900 mb-[48rpx] flex items-center">
            <!-- <IconFont name="user-tie" class="text-blue-500 mr-[16rpx] text-[36rpx]" /> -->
            <IconFont font-class-name="iconfont" class-prefix="icon" name="wode" size="20" class="mr-1" color="#165DFF" />
            <text>个人信息</text>
          </view>

          <nut-form ref="formRef" class="nfome" :model="formData">
            <!-- 真实姓名 -->
            <view class="mb-[48rpx]">
              <text class="block text-[28rpx] font-medium text-blue-800 mb-[16rpx]"> 真实姓名 <text class="text-red-500">*</text> </text>
              <input
                v-model="formData.realName"
                type="text"
                class="w-full box-border px-[25rpx] py-[25rpx] border-2 border-blue-200 rounded-lg text-[26rpx] bg-blue-50"
                placeholder="请输入与身份证一致的姓名"
              />
            </view>

            <!-- 身份证号码 -->
            <view class="mb-[48rpx]">
              <text class="block text-[28rpx] font-medium text-blue-800 mb-[16rpx]"> 身份证号码 <text class="text-red-500">*</text> </text>
              <input
                v-model="formData.realNo"
                type="text"
                class="w-full box-border px-[25rpx] py-[25rpx] border-2 border-blue-200 rounded-lg text-[26rpx] bg-blue-50"
                placeholder="请输入18位身份证号码"
              />
            </view>

            <!-- 上传正面身份证 -->
            <view class="mb-[40rpx]">
              <text class="block text-[28rpx] font-medium text-blue-800 mb-[15rpx]"> 上传正面身份证 <text class="text-red-500">*</text> </text>
              <view
                class="border-2 border-dashed border-gray-200 rounded-[15rpx] p-[40rpx] text-center bg-gray-50 cursor-pointer transition-all"
                :class="uploadedFrontCard ? 'border-blue-600 bg-blue-50' : 'hover:border-blue-600 hover:bg-blue-50'"
                v-if="!uploadedFrontCard"
                @click="uploadIdCard('front')"
              >
                <IconFont
                  font-class-name="iconfont"
                  class-prefix="icon"
                  :name="uploadedFrontCard ? 'file-image' : 'shenfenzhengzhengmian'"
                  class="text-[50rpx] mb-[20rpx]"
                  :class="uploadedFrontCard ? 'text-green-500' : 'text-blue-600'"
                  size="50"
                  color="#4a6bff"
                />
                <text class="text-[26rpx] text-blue-600 block">
                  {{ uploadedFrontCard ? "身份证人像面已上传" : "点击上传身份证正面" }}
                </text>
                <text class="text-[22rpx] text-blue-400 mt-[15rpx] block">
                  {{ uploadedFrontCard ? "点击可重新上传" : "请确保身份证信息清晰可见，支持 JPG/PNG 格式" }}
                </text>
              </view>
              <!-- 显示身份证图片 -->
              <view v-else-if="uploadedFrontCard" class="border-2 border-dashed border-gray-200 flex flex-col items-center justify-center rounded-[15rpx] p-[40rpx] text-center bg-gray-50 cursor-pointer transition-all hover:border-blue-600 hover:bg-blue-50" @click="uploadIdCard('front')">
                <img :src="getFullPath(formData.frontPic)" class="max-w-full max-h-[400rpx] rounded-lg mb-[20rpx]" />
                <view class="text-[24rpx] text-blue-600">
                  <text class="block mb-[10rpx]">身份证正面已上传</text>
                  <text class="text-[20rpx] text-blue-400">点击重新上传</text>
                </view>
              </view>
            </view>

            <!-- 上传国徽面 -->
            <view class="mb-[40rpx]">
              <text class="block text-[28rpx] font-medium text-gray-700 mb-[15rpx]"> 上传反面身份证 <text class="text-red-500">*</text> </text>
              <view
                class="border-2 border-dashed border-gray-200 rounded-[15rpx] p-[40rpx] text-center bg-gray-50 cursor-pointer transition-all"
                :class="uploadedBackCard ? 'border-blue-600 bg-white' : 'hover:border-blue-600 hover:bg-white'"
                v-if="!uploadedBackCard"
                @click="uploadIdCard('back')"
              >
                <IconFont
                  font-class-name="iconfont"
                  class-prefix="icon"
                  :name="uploadedBackCard ? 'file-image' : 'shenfenzhengfanmian2'"
                  class="text-[50rpx] mb-[20rpx]"
                  :class="uploadedBackCard ? 'text-green-500' : 'text-blue-600'"
                  size="50"
                  color="#4a6bff"
                />
                <text class="text-[26rpx] text-blue-600 block">
                  {{ uploadedBackCard ? "身份证已上传" : "点击上传身份证反面" }}
                </text>
                <text class="text-[22rpx] text-blue-400 mt-[15rpx] block">
                  {{ uploadedBackCard ? "点击可重新上传" : "请确保身份证信息清晰可见，支持 JPG/PNG 格式" }}
                </text>
              </view>
              <!-- 显示身份证图片 -->
              <view v-else-if="uploadedBackCard" class="border-2 border-dashed border-gray-200 flex flex-col items-center justify-center rounded-[15rpx] p-[40rpx] text-center bg-gray-50 cursor-pointer transition-all hover:border-blue-600 hover:bg-blue-50" @click="uploadIdCard('back')">
                <img :src="getFullPath(formData.backPic)" class="max-w-full max-h-[400rpx] rounded-lg mb-[20rpx]" />
                <view class="text-[24rpx] text-blue-600">
                  <text class="block mb-[10rpx]">身份证反面已上传</text>
                  <text class="text-[20rpx] text-blue-400">点击重新上传</text>
                </view>
              </view>
            </view>

            <!-- 选择行业 -->
            <view class="mb-[40rpx]" v-if="false">
              <text class="block text-[28rpx] font-medium text-gray-700 mb-[15rpx]"> 选择行业 <text class="text-red-500">*</text> </text>
              <view class="w-full p-[25rpx] text-[26rpx] border-2 border-gray-200 rounded-[15rpx] bg-gray-50" @click="showIndustryPicker = true">
                {{ industryText || "请选择所属行业（可多选）" }}
              </view>

              <nut-popup v-model:visible="showIndustryPicker" position="bottom" round>
                <view class="bg-white p-[40rpx] max-h-[70vh] overflow-auto">
                  <view class="text-[32rpx] font-bold mb-[30rpx] text-center">选择行业（可多选）</view>

                  <view class="space-y-[20rpx]">
                    <view v-for="item in industryOptions" :key="item.value" class="flex items-center p-[20rpx] border-b border-gray-100" @click="toggleIndustry(item.value)">
                      <nut-checkbox :model-value="selectedIndustries.includes(item.value)" class="mr-[20rpx]" />
                      <text class="text-[28rpx]">{{ item.text }}</text>
                    </view>
                  </view>

                  <view class="flex justify-center mt-4 w-full">
                    <nut-button type="primary" class="mt-[40rpx] w-full" @click="onIndustryConfirm"> 确认选择 </nut-button>
                  </view>
                </view>
              </nut-popup>
            </view>

            <!-- 服务范围 -->
            <!-- <view class="mb-[48rpx]">
              <text class="block text-[28rpx] font-medium text-blue-800 mb-[16rpx]"> 服务范围 <text class="text-red-500">*</text> </text>

              <nut-textarea
                v-model="formData.serviceScope"
                placeholder="请详细描述您的服务范围、服务区域及服务内容"
                class="w-full !p-2 !h-[200rpx] box-border border-solid !border-2 !border-gray-500 !rounded-[12rpx] !bg-gray-50"
                maxlength="500"
              />
            </view> -->

            <!-- 上传资质证明 -->
            <view class="mb-[48rpx]" v-if="false">
              <text class="block text-[28rpx] font-medium text-blue-800 mb-[16rpx]"> 上传资质证明 <text class="text-red-500">*</text> </text>
              <view
                class="border-2 border-dashed border-blue-200 rounded-[15rpx] p-[40rpx] text-center bg-blue-50 cursor-pointer"
                :class="uploadedCertificate ? 'border-blue-600 bg-blue-50' : 'hover:border-blue-600 hover:bg-blue-50'"
                v-if="!uploadedCertificate"
                @click="uploadCertificate()"
              >
                <IconFont
                  font-class-name="iconfont"
                  class-prefix="icon"
                  :name="uploadedCertificate ? 'file-image' : 'peixunguanli'"
                  class="text-[50rpx] mb-[20rpx]"
                  :class="uploadedCertificate ? 'text-green-500' : 'text-blue-600'"
                  size="54"
                  color="#4a6bff"
                />
                <text class="text-[26rpx] text-blue-600 block">
                  {{ uploadedCertificate ? "相关资质证明已上传" : "点击上传相关资质证明" }}
                </text>
                <text class="text-[22rpx] text-blue-400 mt-[15rpx] block">
                  {{ uploadedCertificate ? "点击可重新上传" : "如职业证书、作品集、学历证明等（可选）支持 JPG、PNG 格式，大小不超过 5MB" }}
                </text>
              </view>
              <!-- 显示图片 -->
              <view v-else-if="uploadedCertificate" class="border-2 border-dashed border-gray-200 rounded-[15rpx] p-[40rpx] text-center bg-gray-50 cursor-pointer transition-all">
                <img :src="getFullPath(formData.aptitudePic)" />
              </view>
            </view>

            <!-- 押金说明 -->
            <view class="bg-blue-50 border-l-4 border-blue-500 p-[30rpx] rounded-r-lg mb-[48rpx]" v-if="false">
              <view class="text-[28rpx] font-semibold mb-[15rpx] text-blue-500 flex items-center">
                <!-- <IconFont name="shield-alt" class="mr-[10rpx]" /> -->
                <text class="mr-1">🔸</text>
                <text>押金规则说明</text>
              </view>
              <view class="text-[24rpx] text-blue-700">
                <text class="block mb-[10rpx]"
                  >为确保服务质量，您需要缴纳平台保证金：<text class="text-red-500 font-bold text-[32rpx]">¥{{ depositAmount }}</text></text
                >
                <text class="block mb-[10rpx]">审核不通过时，押金将在3-5个工作日内原路退回</text>
                <text class="block">合作期间如无违规行为，保证金在退出平台时全额退还</text>
              </view>
            </view>

            <!-- 协议 -->
            <!-- <view class="mb-[48rpx]">
              <label class="flex items-center">
                <nut-checkbox v-model="formData.agreeTerms">
                  <text class="text-[26rpx]">
                    我已阅读并同意
                    <text class="text-blue-500">《平台服务协议》</text>
                    和
                    <text class="text-blue-500">《隐私政策》</text>
                  </text>
                </nut-checkbox>
              </label>
            </view> -->

            <!-- 提交按钮 -->
            <nut-button 
              type="primary" 
              block 
              size="large" 
              v-if="formData.is_pay != 1 && userStore.userInfo.real_status != 2"
              class="h-[96rpx] text-[32rpx] bg-gradient-to-r from-blue-500 to-blue-600" 
              @click="handleSubmit(status)"
            >
              {{ status ? "提交" : "提交审核申请" }}
            </nut-button>
          </nut-form>
        </view>
      </view>

      <!-- Footer -->
      <!-- <view class="text-center text-blue-600 text-[24rpx]">
        <text class="block">© 2023 自由职业者平台 | 让个人价值得到更好实现</text>
        <view class="flex justify-center gap-[30rpx] mt-[20rpx]">
          <text class="text-blue-500">平台规则</text>
          <text class="text-blue-500">常见问题</text>
          <text class="text-blue-500">联系客服</text>
          <text class="text-blue-500">隐私政策</text>
        </view>
      </view> -->
    </view>
  </view>

  <!-- <ImageUploader></ImageUploader> -->
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import Taro from "@tarojs/taro";
import { IconFont } from "@nutui/icons-vue-taro";
import { post, getFullPath } from "@/utils/request";
import { useUserStore } from "@/store/user";
const userStore = useUserStore();
getIndustryText();

export interface Request {
  // 反面证件
  backPic?: string;
  // 正面证件
  frontPic?: string;
  // 资质证件
  aptitudePic?: string;
  // 证件编号
  id?: number;
  // 行业
  industrys?: string[];
  // 分页查询 第几页
  pageNo?: number;
  // 分页查询 每页多少条
  pageSize?: number;
  // 用户名
  realName?: string;
  // 证件编号
  realNo?: string;
  // 服务范围
  serviceScope?: string;
  // 商家类型
  type?: string;
  agreeTerms?: boolean;
  [property: string]: any;
}

// 表单数据
const formData = ref<Request>({});

// 行业相关
const industryOptions = ref<{ text: string; value: number }[]>([]);
// 修改行业选择相关状态
const showIndustryPicker = ref(false);
const selectedIndustries = ref<number[]>([]); // 存储选中的行业ID
const industryText = ref("");

// 获取行业列表
function getIndustryText() {
  post("/dictionary/industry").then((res) => {
    industryOptions.value = res.data.map((item: any) => ({
      text: item.columns.name,
      value: item.columns.id,
    }));
  });
}

// 处理行业选择确认
function onIndustryConfirm() {
  showIndustryPicker.value = false;

  // 生成行业名称文本
  const selectedNames = industryOptions.value.filter((item: { text: string; value: number }) => selectedIndustries.value.includes(item.value)).map((item: { text: string; value: number }) => item.text);

  industryText.value = selectedNames.join("、");

  // 保存行业ID数组
  formData.value.industrys = selectedIndustries.value.map(id => id.toString());
}

// 切换行业选择状态
function toggleIndustry(id: number) {
  const index = selectedIndustries.value.indexOf(id);
  if (index > -1) {
    selectedIndustries.value.splice(index, 1);
  } else {
    selectedIndustries.value.push(id);
  }
}
// 状态
const uploadedFrontCard = ref(false);
const uploadedBackCard = ref(false);
const uploadedCertificate = ref(false);

// 表单引用
const formRef = ref();

// 上传身份证
const uploadIdCard = (type: string) => {
  // try {
  //   Taro.showLoading({ title: '上传中...' })
  //   const uploadRes = await Taro.uploadFile({
  //     url:getFullPath('/file/upload'),
  //     filePath,
  //     name: 'file',
  //     header: {
  //       'token': Taro.getStorageSync('token') ? Taro.getStorageSync('token') : ''
  //     }
  //   })
  //   Taro.hideLoading()
  //   const data = JSON.parse(uploadRes.data)
  //   if (data.code === 0) {
  //     if(targetPathRef===1){
  //       courseForm.value.coverUrl = data.data
  //     }else if (targetPathRef===2){
  //       courseForm.value.teacherPic = data.data
  //     }
  //     //console.log("targetPathRef",targetPathRef)
  //     showToast({ title: '上传成功', icon: 'success' })
  //   } else {
  //     showToast({ title: data.message || '上传失败', icon: 'none' })
  //   }
  // } catch (err) {
  //   Taro.hideLoading()
  //   showToast({ title: '上传失败', icon: 'none' })
  // }
  // 上传逻辑
  Taro.chooseImage({
    count: 1,
    sizeType: ["original", "compressed"],
    sourceType: ["album", "camera"],
    success: async (res) => {
      console.log(res);
      Taro.showLoading({ title: "上传中..." });
      const uploadRes = await Taro.uploadFile({
        url: getFullPath("/file/upload"),
        filePath: res.tempFilePaths[0],
        name: "file",
        header: {
          token: Taro.getStorageSync("token"),
        },
      });
      Taro.hideLoading();
      const data = JSON.parse(uploadRes.data);
      if (type == "front") {
        // 保存url地址
        formData.value.frontPic = data.data;
        console.log("正面===>", getFullPath(formData.value.frontPic));
        uploadedFrontCard.value = true;
        Taro.showToast({
          title: "身份证正面上传成功",
          icon: "success",
        });
      } else {
        // 保存url地址
        formData.value.backPic = data.data;
        console.log("反面===>", getFullPath(formData.value.backPic));
        uploadedBackCard.value = true;
        Taro.showToast({
          title: "身份证反面上传成功",
          icon: "success",
        });
      }
    },
  });
};

// 上传资质证明
const uploadCertificate = () => {
  Taro.chooseImage({
    count: 1,
    sizeType: ["original", "compressed"],
    sourceType: ["album", "camera"],
    success: async (res) => {
      console.log(res);
      Taro.showLoading({ title: "上传中..." });
      const uploadRes = await Taro.uploadFile({
        url: getFullPath("/file/upload"),
        filePath: res.tempFilePaths[0],
        name: "file",
        header: {
          token: Taro.getStorageSync("token"),
        },
      });
      Taro.hideLoading();
      const data = JSON.parse(uploadRes.data);
      // 保存url地址
      formData.value.aptitudePic = data.data;
      uploadedCertificate.value = true;
      Taro.showToast({
        title: "资质证明上传成功",
        icon: "success",
      });
    },
  });
};

// 提交表单
const handleSubmit = async (status: string) => {
  // if (status) {
  //   Taro.showToast({
  //     title: "正在审核中,请等待!",
  //     icon: "none",
  //   });
  //   return;
  // }
  // console.log(formData.value);
  // 表单验证
  if (!formData.value.realName) {
    Taro.showToast({
      title: "请输入真实姓名",
      icon: "none",
    });
    return;
  }

  if (!formData.value.realNo || formData.value.realNo.length !== 18) {
    Taro.showToast({
      title: "请输入有效的18位身份证号码",
      icon: "none",
    });
    return;
  }
  if (!uploadedFrontCard.value) {
    Taro.showToast({
      title: "请上传正面身份证",
      icon: "none",
    });
    return;
  }
  if (!uploadedBackCard.value) {
    Taro.showToast({
      title: "请上传反面身份证",
      icon: "none",
    });
    return;
  }
  console.log(formData.value.industrys);
  // if (!formData.value.industrys?.length) {
  //   Taro.showToast({
  //     title: "请选择所属行业",
  //     icon: "none",
  //   });
  //   return;
  // }

  // if (!formData.value.serviceScope) {
  //   Taro.showToast({
  //     title: "请填写服务范围",
  //     icon: "none",
  //   });
  //   return;
  // }

  // if (!formData.value.agreeTerms) {
  //   Taro.showToast({
  //     title: "请阅读并同意平台协议",
  //     icon: "none",
  //   });
  //   return;
  // }

  // if (!uploadedCertificate) {
  //   Taro.showToast({
  //     title: "请上传资质证明",
  //     icon: "none",
  //   });
  //   return;
  // }

  // // 提交成功
  // Taro.showToast({
  //   title: "申请提交成功！我们将在1-3个工作日内完成审核，请留意平台通知。",
  //   icon: "success",
  //   duration: 3000,
  // });
  // 支付--传入业务id
  // payDeposit();
  const res = await post("/user/realName", formData.value);
  console.log("个人认证====>", res);
  if (res.code == "0") {
    Taro.showToast({
      title: "申请提交成功！我们将在1-3个工作日内完成审核，请留意平台通知。",
      icon: "success",
      duration: 3000,
    });
    // payDeposit();
  }
};

// 押金金额
const depositAmount = ref(100); // 测试




// 获取认证状态参数
const status = Taro.getCurrentInstance().router?.params.status || '';
const getAuthentication = async () => {
  if (status) {
    try {
      const res = await post("/user/getAuthentication");
      if (res.code == 0) {
        const data = res.data.columns;
        
        // 基础信息赋值
        formData.value.backPic = data.back_pic || ''; // 反面证件 -> 反面图片
        formData.value.frontPic = data.front_pic || ''; // 正面证件 -> 正面图片
        formData.value.aptitudePic = data.aptitude_pic || ''; // 资质证件 -> 资质证件图片
        formData.value.id = data.id || 0; // 证件编号 -> ID
        formData.value.realName = data.real_name || ''; // 用户名 -> 真实姓名
        formData.value.realNo = data.real_no || ''; // 证件编号 -> 身份证号
        formData.value.serviceScope = data.service_scope || ''; // 服务范围 -> 服务范围
        formData.value.is_pay = data.is_pay || 0; // 是否支付
        
        // 根据是否有图片数据设置上传状态
        uploadedFrontCard.value = !!data.front_pic;
        uploadedBackCard.value = !!data.back_pic;
        uploadedCertificate.value = !!data.aptitude_pic;
        
        // 服务范围处理 - 如果是数组，转换为字符串
        if (data.service_scope && Array.isArray(data.service_scope)) {
          formData.value.serviceScope = data.service_scope.join('、');
        }
        
        // 行业处理 - 提取行业ID数组
        if (data.industrys && Array.isArray(data.industrys)) {
          const industryIds = data.industrys.map((item: any) => {
            if (item.columns && item.columns.industry_id) {
              return parseInt(item.columns.industry_id);
            }
            return null;
          }).filter((id: any) => id !== null);
          
          // 转换为字符串数组以匹配接口类型
          formData.value.industrys = industryIds.map((id: any) => id.toString());
          selectedIndustries.value = industryIds;
          
          // 更新行业显示文本
          if (industryIds.length > 0) {
            const industryNames = industryIds.map((id: any) => {
              const option = industryOptions.value.find((opt: any) => opt.value === id);
              return option ? option.text : '';
            }).filter((name: any) => name !== '');
            industryText.value = industryNames.join('、');
          }
        } else {
          formData.value.industrys = [];
          selectedIndustries.value = [];
          industryText.value = '';
        }
        
        // 调试信息
        console.log('表单数据已更新:', formData.value);
        console.log('上传状态:', {
          uploadedFrontCard: uploadedFrontCard.value,
          uploadedBackCard: uploadedBackCard.value,
          uploadedCertificate: uploadedCertificate.value
        });
        console.log('图片路径调试:');
        console.log('身份证正面:', data.front_pic, '状态:', uploadedFrontCard.value);
        console.log('身份证反面:', data.back_pic, '状态:', uploadedBackCard.value);
        console.log('资质证明:', data.aptitude_pic, '状态:', uploadedCertificate.value);
        console.log('完整图片路径:');
        console.log('身份证正面完整路径:', getFullPath(data.front_pic || ''));
        console.log('身份证反面完整路径:', getFullPath(data.back_pic || ''));
        console.log('资质证明完整路径:', getFullPath(data.aptitude_pic || ''));
        
      } else {
        console.error('获取认证信息失败:', res.message);
        Taro.showToast({
          title: res.message || '获取认证信息失败',
          icon: 'error',
          duration: 2000
        });
      }
    } catch (error) {
      console.error('获取认证信息异常:', error);
      Taro.showToast({
        title: '网络错误，请重试',
        icon: 'error',
        duration: 2000
      });
    }
  }
};

// 页面加载时获取认证信息
onMounted(() => {
  getAuthentication();
});
</script>

<style lang="scss">
.bgs {
  .nut-cell-group__wrap {
    box-shadow: none !important;
  }

  .nut-textarea {
    padding: 0 !important;
  }
}
</style>
